<!-- 通讯录 -->
<template>
	<!-- <view class="header">
		<view class="body">
			<view class="header-inpput">
				<image class="icon" src="/static/wx/communication.svg" @click="onIconClick"></image>
				<input v-model="searchQuery" class="search-input" placeholder="搜索联系人" />
			</view>
			<view class="alphabet">
				<span v-for="letter in alphabet" :key="letter" @click="scrollToLetter(letter)">
					{{ letter }}
				</span>
			</view>
			<view class="contacts">
				<view v-for="(group, key) in groupedContacts" :key="key">
					<h2>{{ key }}</h2>
					<ul>
						<li v-for="contact in group" :key="contact.id" class="item">
							<image :src="contact.img" mode="aspectFill" class="img" alt="avatar"></image>
							<span>
								{{ contact.name }}
							</span>
						</li>
					</ul>
				</view>
			</view>
			<view class="list-cell">
				<view v-for="contact in contacts" :key="contact.id" class="item-cell">
					<image :src="contact.img" mode="aspectFill" class="img"></image>
					<view>{{ contact.name }}</view>
				</view>
			</view>
		</view>
	</view> -->
	<!--	<view class="group-member-page">
		<view :style="{ height: statusBarHeight + 'px' }"></view>
		<view class="nav-container">
			<view class="nav-back" @click="goBack">
				<image class="nav-back-img" src="https://img.yiqitogether.com/static/local/index/back@2x.png" mode="">
				</image>
			</view>
			&lt;!&ndash; 搜索 &ndash;&gt;
			<view class="nav-search">
				<image class="search-icon" src="/static/wx/communication.svg" mode=""></image>
				<input class="search-input" v-model.trim="inputValue" type="text" placeholder="搜索成员"
					placeholder-style="color: #ADB3BA" @input="onSearch" />
				<image src="@/static/images/myImgs/del@2x.png" class="del-icon" v-show="inputValue" @click="onClear"
					mode=""></image>
			</view>
		</view>
		<view class="main-container">
			&lt;!&ndash; 成员列表 &ndash;&gt;
			<view class="">
				<view class="list-wrap"
					v-if="(initiatorInfo.displayName || initiatorInfo.nickName) && showInitiatorInfo">
				</view>
				<scroll-view v-if="memberList" :scroll-y="true">
					<view></view>
				</scroll-view>
			</view>
		</view>
	</view>-->
	<div>
		<div class="header">
			<input type="text" v-model="keyword" placeholder="搜索联系人" />
		</div>
		<div class="contacts-list">
			<ul>
				<li v-for="contact in filteredContacts" :key="contact.id">
					<image src="contact.img" mode="aspectFill" class="img"></image>
					<div class="avatar">{{ contact.name[0] }}</div>
					<div class="info">
						<div class="name">{{ contact.name }}</div>
						<div class="message">{{ contact.message }}</div>
					</div>
					<div class="time">{{ contact.time }}</div>
				</li>
			</ul>
		</div>
	</div>
</template>

<script>
import { computed } from "vue"
	data() {
		return {
			keyword: '',
			contacts: [{
					id: 1,
					img: '/static/img/avatar/avatar1.jpg',
					name: '张三',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 2,
					img: '/static/img/avatar/avatar1.jpg',
					name: '李四',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 3,
					img: '/static/img/avatar/avatar1.jpg',
					name: '王五',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 4,
					img: '/static/img/avatar/avatar1.jpg',
					name: '阿权',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 5,
					img: '/static/img/avatar/avatar1.jpg',
					name: '磨合',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 6,
					img: '/static/img/avatar/avatar1.jpg',
					name: '驾鹤西去',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 7,
					img: '/static/img/avatar/avatar1.jpg',
					name: '张四',
					message: '吃了吗',
					time: "15:31"
				},
				{
					id: 8,
					img: '/static/img/avatar/avatar1.jpg',
					name: '张三丰',
					message: '吃了吗',
					time: "15:31"
				}
			]
		}
	},
	computed: {
		filteredContacts() {
			return this.contacts.filter(contact => {
				return contact.name.toLowerCase().includes(this.keyword.toLowerCase());
			});
		}
	}
	/* import {
		ref,
		computed
	} from "vue"
	import pinyin from "js-pinyin"
	// const searchQuery = ref('')
	const contacts = ref([{
			id: 1,
			img: '/static/img/avatar/avatar1.jpg',
			name: '张三',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 2,
			img: '/static/img/avatar/avatar1.jpg',
			name: '李四',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 3,
			img: '/static/img/avatar/avatar1.jpg',
			name: '王五',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 4,
			img: '/static/img/avatar/avatar1.jpg',
			name: '阿权',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 5,
			img: '/static/img/avatar/avatar1.jpg',
			name: '磨合',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 6,
			img: '/static/img/avatar/avatar1.jpg',
			name: '驾鹤西去',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 7,
			img: '/static/img/avatar/avatar1.jpg',
			name: '张四',
			message: '吃了吗',
			time: "15:31"
		},
		{
			id: 8,
			img: '/static/img/avatar/avatar1.jpg',
			name: '张三丰',
			message: '吃了吗',
			time: "15:31"
		},
	]) */
	// const alphabet = 'ABCDEFGHIGKLMNOPQRSTUVWXYZ'.split('')

	// const filteredContacts = computed(() => {
	// 	return contacts.value.filter(
	// 		contact => contact.name.includes(searchQuery.value)
	// 	);
	// });

	// // 将汉字转换为拼音首字母
	// /* function getInitials(name) {
	// 	const initials = pinyin(name, {
	// 		style: pinyin.STYLE_FIRST_LETTER
	// 	});
	// 	return initials[0][0].toUpperCase();
	// } */

	// // 计算属性, 用于根据首字母分组
	// const groupedContacts = computed(() => {
	// 	const grouped = {};
	// 	contacts.value.forEach((contact) => {
	// 		// const letter = getInitials(contact.name);
	// 		const letter = contact.name[0].toUpperCase();
	// 		if (!grouped[letter]) {
	// 			grouped[letter] = [];
	// 		}
	// 		grouped[letter].push(contact);
	// 	});
	// 	return grouped;
	// });

	// // 计算属性, 用于分组进行排序并替换分组名称
	// /* const sortedGroupedContacts = computed(() => {
	// 	const { groupedContacts: grouped } = this;
	// 	const sortedKeys = Object.keys(grouped).sort((a, b) => a.localeCompare(b))
	// 	const sortedGrouped = {};
	// 	sortedKeys.forEach(key => {
	// 		sortedGrouped[key] = grouped[key];
	// 	});
	// 	return sortedGrouped;
	// }) */

	// // const groupedContacts = computed(() => {
	// // 	const group = [];
	// // 	const lettrs = new Set();

	// // 	filteredContacts.value.forEach(contact => {
	// // 		const letter = contact.name.charAt(0).toUpperCase(); /* 获取联系人首字母并转换为大写*/
	// // 		if (!letters.has(letter)) { /* 如果字母未存在于集合中*/
	// // 			letters.add(letter); /* 添加字母到集合*/
	// // 			groups.push({ letter, contact: []}); /* 创建新的分组*/
	// // 		}
	// // 		const group = group.find(g => g.letter === letter); /* 查找对应的分组*/
	// // 		if (group) {
	// // 			group.contacts.push(contact); /* 将联系人添加到分组中*/
	// // 		}
	// // 	});
	// // 	return group; /* 返回分组联系人*/
	// // });

	// const scrollToLetter = (letter) => {
	// 	/* 定义滚动到字母的函数*/
	// 	const element = document.getElementById(letter); /* 获取对应字母的元素*/
	// 	if (element) {
	// 		element.scrollIntoView({
	// 			behavior: 'smooth'
	// 		})
	// 	}
	// }

	// const onIconClick = () => {
	// 	/* 定义图标点击事件处理方式 */
	// 	uni.showToast({
	// 		title: '搜索内容: ' + searchQuery.value
	// 	})
	// }
</script>

<style>
	.header {
		padding: 10px;
		background-color: #F5F5F5;
	}

	.header input {
		width: 100%;
		padding: 5px 10px;
		border: 1px solid #ccc;
		border-radius: 4px;
	}

	.contacts-list {
		margin-top: 20px;
	}

	.contacts-list ul {
		list-style-type: none;
		padding: 0;
	}

	.contacts-list li {
		display: flex;
		align-items: center;
		padding: 10px;
		border-bottom: 1px solid #ccc;
	}

	.avatar {
		width: 40px;
		height: 40px;
		background-color: #ccc;
		border-radius: 50%;
		text-align: center;
		line-height: 40px;
		margin-right: 10px;
		font-size: 20px;
		color: #fff;
	}

	.info {
		flex-grow: 1;
	}


	.img {
		width: 76rpx;
		height: 76rpx;
		border-radius: 12rpx;
		flex: 0 0 76rpx;
	}
	
	.name {
		font-size: 16px;
		font-weight: bold;
	}
	
	.message {
		font-size: 14px;
		color: #999;
	}
	
	.time {
		font-size: 14px;
		color: #999;
	}
</style>